package com.school.chapter02.queue_;

@SuppressWarnings({"all"})
public class Queue_<T>  {
    Object[] data;
    int size;
    int front = 0;
    int rear =0;
    public Queue_( ){}
    public Queue_(int size){
        this.size = size;
        this.data = new Object[size];
    }
    public boolean enqueue(T t) {
        if(isFull())return false;
        data[rear]=t;
        rear=(rear+1)%size;
        return true;
    }
    public int length(){
        return (rear-front+size)%size;
    }

    public T dequeue() {
        if(isEmpty())return null;
        T t = (T) data[front];
        data[front]=null;
        front=(front+1)%size;
        return t;
    }
    public boolean isEmpty(){
        if(rear==front)return true;
        return false;
    }
    public boolean isFull() {
        if((rear+1)%size==front)return true;
        return false;
    }
    public int size() {
        return size;
    }
    public T getFront(){
        return (T)data[front];
    }
}